import Mock from 'mockjs'
import { result, getNowTime, mockPageRes, qsparse } from '../util'
const mockproductInfoList = (params) => result(() => {
  let list1 = []
  const p1 = { productCode: 'P0001', status: 1, productName: '滚珠丝杆', price: 19.89, tag: 1, model: 'M0012', remark: '热情我去问人', showPic: '', creater: '刘丽', updateTime: getNowTime(), createTime: getNowTime() }
  const p2 = { productCode: 'P0002', status: 0, productName: 'LGD导轨', price: 20.11, tag: 3, model: 'M0014', remark: '二二二', showPic: '', creater: '刘丽', updateTime: getNowTime(), createTime: getNowTime() }
  const p3 = { productCode: 'P0003', status: 0, productName: 'LGD导轨2', price: 90.80, tag: 3, model: 'M0015', remark: '测试', showPic: '', creater: '刘丽', updateTime: getNowTime(), createTime: getNowTime() }
  const p4 = { productCode: 'P0004', status: 0, productName: 'LGD导轨4', price: 90.80, tag: 3, model: 'M0015', remark: '测试', showPic: '', creater: '刘丽', updateTime: getNowTime(), createTime: getNowTime() }
  const p5 = { productCode: 'P0005', status: 0, productName: 'LGD导轨5', price: 90.80, tag: 3, model: 'M0015', remark: '测试', showPic: '', creater: '刘丽', updateTime: getNowTime(), createTime: getNowTime() }
  list1.push(p1, p2, p3, p4, p5)
  const status = [0, 1]
  const tag = [1, 2, 3]
  list1 = Mock.mock({
    'list|12': [
      {
        'productCode': /P[0-9]{7}/,
        'productName': '@ctitle(5)',
        'status|1': status,
        'price|100-900.2-2': 200,
        'model': /M[0-9]{3}[a-z]{3}/,
        'tag|1': tag,
        'remark': '@ctitle(10)',
        'showPic': "@image('30x30', '@color','#FFF', 'png','P')",
        'createTime': '@now',
        'updateTime': '@now',
        'creater': '@cname'
      }
    ]
  }).list
  return mockPageRes(params, list1)
})

const mockPorductTage = result(() => {
  const tagOptions = [
    {
      value: 1,
      label: '滚珠丝杆'
    },
    {
      value: 2,
      label: '直线导轨'
    },
    {
      value: 3,
      label: '导轨'
    },
    {
      value: 4,
      label: '机床丝杆'
    },
    {
      value: 5,
      label: '联轴器'
    },
    {
      value: 6,
      label: '其他轴承附属'
    }
  ]
  return tagOptions
})
const mockSalesProductInfoList = (params) => result(() => {
  const tagText = ['滚珠丝杆', '直线导轨']
  const tag = [1, 2]
  const info = Mock.mock({
    'list|10': [{
      'productCode|+1': /P[0-9]{7}/,
      'productName': '@ctitle(8,15)',
      'price|100-1000.2-2': 100,
      'tagText|+1': tagText,
      'tag|+1': tag,
      'model': /M[0-9]{7}/,
      'remark': '@cparagraph',
      'status|0-1': 0,
      'showPic': "@image('200x200', '#409eff','#FFF', 'png','P')",
      'stockCount|10-20': 10
    }]
  })
  const list = info.list
  return mockPageRes(params, list)
})
export default {
  'post|/api/getProductList': (option) => {
    const params = qsparse(option.body)
    return mockproductInfoList(params)
  },
  'post|/api/getAllProductTag': mockPorductTage,
  'post|product/getSalesProductInfoList': (option) => {
    const params = qsparse(option.body)
    return mockSalesProductInfoList(params)
  }
}
